package com.zy.utils;

import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.security.Keys;

import java.util.Base64;

/**
 * @program: shopping153_cloud
 * @description: 生成token的密钥
 * @author: zy
 * @create: 2025-08-28 11:07
 */
public class SecretKeyGeneratorUtilsTest {
    public static void main(String[] args) {
        //生成 基于HS256算法的密钥   256bit=32字节
        byte[] keyBytes = Keys.secretKeyFor(SignatureAlgorithm.HS256).getEncoded();
        //将以上的字节数组转换为base64编码的字符串
        String base64EncodedKey = Base64.getEncoder().encodeToString(keyBytes);
        System.out.println( "生成的Base64编码的密钥为：" + base64EncodedKey);

        ////////////解码
        byte[] decodedKey = Base64.getDecoder().decode(base64EncodedKey);
        System.out.println( "解码后的密钥为：" + decodedKey.length);
    }
}
